#!/usr/bin/python
"""
log rotaging utility

ex.)
yes | ./logger.py logfile

"""

import sys
import logging
import logging.handlers

log = logging.getLogger()
if not log:
    sys.exit(1)

hdl = logging.handlers.TimedRotatingFileHandler(sys.argv[1], "D", 1, 31)
formatter = logging.Formatter('%(asctime)s %(message)s')
hdl.setFormatter(formatter)
BUFF_SIZE=1024*1024*10 # 10 MB
bufhdl = logging.handlers.MemoryHandler(BUFF_SIZE, logging.INFO, hdl)
log.addHandler(bufhdl)
log.setLevel(logging.INFO)

while True:
    try:
        l = sys.stdin.readline()
        if not l:
            break;
        log.info(l.rstrip())
    except :
        break


